import Vue from 'vue'
import Vuex from 'vuex'
import createLogger from 'vuex/dist/logger'
import user from './module/user'
import viewState from './module/view-state'
import common from './module/common'
import logs from './module/logs'
import message from './module/message'
import config from './module/config'
import im from './module/im'
import createPersistedState from 'vuex-persistedstate'

Vue.use(Vuex)

const plugins = [
  createPersistedState({
    key: 'fuyao-cloud',
    paths: ['viewState.theme', 'viewState.themeColor'],
    filter(mutation) {
      return ['viewState/setTheme', 'viewState/setThemeColor'].includes(mutation.type)
    }
  })
]

if (process.env.VUE_APP_VUEX_LOG === 'Y') {
  plugins.push(createLogger())
}

export default new Vuex.Store({
  modules: {
    logs,
    message,
    config,
    common,
    user,
    viewState,
    im
  },
  plugins
})
